layui.use(['form', 'laydate'], function () {
    var form = layui.form;
    var layer = layui.layer;
    var  $ = layui.jquery;
    var laydate = layui.laydate;


    //日期
    laydate.render({
        elem: '#date'
    });
    laydate.render({
        elem: '#date1'
    });

    // 提交事件
    form.on('submit(submit_val)', function (data) {
        var field = data.field; // 获取表单字段值
        console.log(field);
        // 请求的地址
        var url = ctx + "/discount/discountAdd"; // 添加操作

        layer.confirm('确定提交吗？', function (index) {
            layer.close(index); // 关闭确认提示框

            $.ajax({
                type: "post",
                url: url,
                data: {
                    type: field.type,
                    name: field.name,
                    platform: field.platform,
                    count: field.count,
                    amount: field.amount,
                    perLimit: field.perLimit,
                    minPoint: field.minPoint,
                    enableTime: field.enableTime,
                    startTime: field.startTime,
                    endTime: field.endTime,
                    useType: field.useType
                },
                success: function (result) {
                    // 判断是否添加成功
                    if (result.code == 200) {

                        // 优惠券添加成功，跳转到优惠券查询页面
                        layer.msg("优惠券添加成功，系统将在3秒钟后刷新", function () {
                            // 跳转到优惠券查询页面
                            location.reload();
                        });

                    } else {
                        layer.msg(result.msg, {icon: 5});
                    }
                }
            })
        });
        return false;
    });

});